<template>
  <div class="start-container">
    <div class="tech-bg"></div>

    <div class="tech-particles">
      <div class="particle p1"></div>
      <div class="particle p2"></div>
      <div class="particle p3"></div>
      <div class="particle p4"></div>
      <div class="particle p5"></div>
      <div class="particle p6"></div>
      <div class="particle p7"></div>
      <div class="particle p8"></div>
    </div>

    <div class="welcome-content" :class="{ show: isActive }">
      <div class="tech-circles">
        <div class="circle c1"></div>
        <div class="circle c2"></div>
        <div class="circle c3"></div>
      </div>

      <div class="welcome-text">
        <h1>欢迎进入车辆管理系统</h1>
        <div class="loading-bar">
          <div class="progress" :style="{ width: progress + '%' }"></div>
        </div>
      </div>
    </div>

    <div class="corner corner-tl"></div>
    <div class="corner corner-tr"></div>
    <div class="corner corner-bl"></div>
    <div class="corner corner-br"></div>
  </div>
</template>

<script setup>
import { ref, onMounted } from "vue";
import { useRouter } from "vue-router";
import { useCarStore } from "@/stores/dataStore";
const carStore = useCarStore();
const { fetchCarInfo } = carStore;

const router = useRouter();
const isActive = ref(false);
const progress = ref(0);

onMounted(() => {
  // 延迟触发动画
  fetchCarInfo();
  setTimeout(() => {
    isActive.value = true;
  }, 300);

  // 进度条动画
  const interval = setInterval(() => {
    if (progress.value < 100) {
      progress.value += 1;
    } else {
      clearInterval(interval);
    }
  }, 30);

  // 3秒后跳转到carList页面
  setTimeout(() => {
    router.push("/carList");
  }, 3000);
});
</script>

<style scoped>
.start-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #050b1f;
  margin: 0;
  padding: 0;
}

.tech-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(
      circle at 20% 30%,
      rgba(41, 97, 255, 0.1) 0%,
      transparent 40%
    ),
    radial-gradient(
      circle at 80% 70%,
      rgba(0, 212, 255, 0.1) 0%,
      transparent 40%
    ),
    radial-gradient(
      circle at 50% 50%,
      rgba(0, 100, 255, 0.05) 0%,
      transparent 60%
    ),
    linear-gradient(135deg, rgba(6, 11, 40, 0.8) 0%, rgba(10, 15, 35, 0.9) 100%);
  z-index: 1;
  overflow: hidden;
}

.tech-bg::before {
  content: "";
  position: absolute;
  width: 200%;
  height: 200%;
  top: -50%;
  left: -50%;
  background-image: linear-gradient(
      transparent 0%,
      transparent 40%,
      rgba(0, 150, 255, 0.1) 40%,
      transparent 60%
    ),
    linear-gradient(
      90deg,
      transparent 0%,
      transparent 40%,
      rgba(0, 150, 255, 0.1) 40%,
      transparent 60%
    );
  background-size: 60px 60px;
  animation: gridMove 20s linear infinite;
  opacity: 0.3;
}

@keyframes gridMove {
  0% {
    transform: translateY(0) rotate(0deg);
  }
  100% {
    transform: translateY(60px) rotate(1deg);
  }
}

.tech-particles {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  z-index: 1;
}

.particle {
  position: absolute;
  width: 2px;
  height: 2px;
  background: rgba(0, 242, 254, 0.6);
  border-radius: 50%;
  box-shadow: 0 0 6px rgba(0, 242, 254, 0.8);
}

.p1 {
  top: 20%;
  left: 10%;
  animation: float 15s infinite ease-in-out;
}
.p2 {
  top: 30%;
  left: 30%;
  animation: float 18s infinite ease-in-out;
  animation-delay: 1s;
}
.p3 {
  top: 70%;
  left: 65%;
  animation: float 20s infinite ease-in-out;
  animation-delay: 2s;
}
.p4 {
  top: 40%;
  left: 80%;
  animation: float 17s infinite ease-in-out;
  animation-delay: 3s;
}
.p5 {
  top: 60%;
  left: 20%;
  animation: float 16s infinite ease-in-out;
  animation-delay: 4s;
}
.p6 {
  top: 80%;
  left: 40%;
  animation: float 19s infinite ease-in-out;
  animation-delay: 5s;
}
.p7 {
  top: 10%;
  left: 60%;
  animation: float 14s infinite ease-in-out;
  animation-delay: 6s;
}
.p8 {
  top: 50%;
  left: 50%;
  animation: float 21s infinite ease-in-out;
  animation-delay: 7s;
}

@keyframes float {
  0% {
    transform: translate(0, 0);
  }
  25% {
    transform: translate(20px, 15px);
  }
  50% {
    transform: translate(10px, 30px);
  }
  75% {
    transform: translate(-10px, 15px);
  }
  100% {
    transform: translate(0, 0);
  }
}

.welcome-content {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  opacity: 0;
  transform: scale(0.9);
  transition: all 1s ease-out;
}

.welcome-content.show {
  opacity: 1;
  transform: scale(1);
}

.tech-circles {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
}

.circle {
  position: absolute;
  border-radius: 50%;
  border: 2px solid rgba(0, 242, 254, 0.3);
  box-shadow: 0 0 20px rgba(0, 100, 255, 0.3);
  opacity: 0;
  transform: translate(-50%, -50%);
}

.welcome-content.show .circle {
  animation: pulse 3s infinite;
}

.c1 {
  width: 300px;
  height: 300px;
  top: 50%;
  left: 50%;
  animation-delay: 0s !important;
}

.c2 {
  width: 500px;
  height: 500px;
  top: 50%;
  left: 50%;
  animation-delay: 0.5s !important;
}

.c3 {
  width: 700px;
  height: 700px;
  top: 50%;
  left: 50%;
  animation-delay: 1s !important;
}

@keyframes pulse {
  0% {
    transform: translate(-50%, -50%) scale(0.8);
    opacity: 0;
  }
  50% {
    opacity: 0.5;
  }
  100% {
    transform: translate(-50%, -50%) scale(1.2);
    opacity: 0;
  }
}

.welcome-text {
  position: relative;
  color: #fff;
  font-size: 3rem;
  z-index: 3;
  text-align: center;
  text-shadow: 0 0 20px rgba(0, 100, 255, 0.8);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(5, 11, 31, 0.5);
  padding: 30px 50px;
  border-radius: 10px;
  box-shadow: 0 0 30px rgba(0, 100, 255, 0.2);
  backdrop-filter: blur(5px);
  border: 1px solid rgba(0, 242, 254, 0.2);
}

h1 {
  margin: 0;
  font-weight: bold;
  background: linear-gradient(45deg, #00f2fe, #4facfe);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 2px;
  margin-bottom: 20px;
}

.loading-bar {
  width: 300px;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  overflow: hidden;
  margin: 0 auto;
}

.progress {
  height: 100%;
  background: linear-gradient(90deg, #00f2fe, #4facfe);
  transition: width 0.3s ease;
  box-shadow: 0 0 10px rgba(0, 242, 254, 0.5);
}

.corner {
  position: absolute;
  width: 30px;
  height: 30px;
  border: 2px solid #00f2fe;
  z-index: 3;
  box-shadow: 0 0 10px rgba(0, 242, 254, 0.5);
}

.corner-tl {
  top: 20px;
  left: 20px;
  border-right: none;
  border-bottom: none;
}

.corner-tr {
  top: 20px;
  right: 20px;
  border-left: none;
  border-bottom: none;
}

.corner-bl {
  bottom: 20px;
  left: 20px;
  border-right: none;
  border-top: none;
}

.corner-br {
  bottom: 20px;
  right: 20px;
  border-left: none;
  border-top: none;
}
</style>
